package com.wh.base.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.wh.base.sys.user.service.UserService;

import cn.dev33.satoken.stp.StpInterface;

/**
 * 自定义权限验证接口扩展 
 */
@Component    // 保证此类被SpringBoot扫描，完成Sa-Token的自定义权限验证扩展 
public class StpInterfaceImpl implements StpInterface{
	
	@Autowired
	private UserService userService;
	
	@Override
	public List<String> getPermissionList(Object loginId, String loginType) {
		long userId = 0L;
		if(loginId instanceof String) {
			userId = Long.parseLong((String)loginId);
		}else if(loginId instanceof Integer) {
			userId = (int)loginId + 0L;
		}else {
			userId = (long)loginId;
		}
		
		return new ArrayList<>(userService.getAuthSignListByUserId(userId));
	}

	@Override
	public List<String> getRoleList(Object loginId, String loginType) {
		long userId = 0L;
		if(loginId instanceof String) {
			userId = Long.parseLong((String)loginId);
		}else if(loginId instanceof Integer) {
			userId = (int)loginId + 0L;
		}else {
			userId = (long)loginId;
		}
		return userService.getRoleListByUserId(userId);
	}

}
